#include "APZP1AlgorithmDesigner.h"
#include "ui_APZP1AlgorithmDesigner.h"

APZP1AlgorithmDesigner::APZP1AlgorithmDesigner(QWidget *parent) :
    AdaptiveAlgorithmDesignerBase(parent),
    ui(new Ui::APZP1AlgorithmDesigner)
{
    ui->setupUi(this);
}

APZP1AlgorithmDesigner::~APZP1AlgorithmDesigner()
{
    delete ui;
}

void APZP1AlgorithmDesigner::attachAlgorithm(RafMat::SimInterface::IConfigurableSPtr ctrl)
{
    m_targetAlgorithm = ctrl;

    try
    {
        ui->edAmPoly->setText(QString::fromStdString(m_targetAlgorithm->getParameter("adpt::ampoly")));
        ui->edBmPoly->setText(QString::fromStdString(m_targetAlgorithm->getParameter("adpt::bmpoly")));
        ui->edRDegree->setValue(QString::fromStdString(m_targetAlgorithm->getParameter("adpt::ndr")).toDouble());
        ui->edSDegree->setValue(QString::fromStdString(m_targetAlgorithm->getParameter("adpt::nds")).toDouble());
        ui->edKDelay->setValue(QString::fromStdString(m_targetAlgorithm->getParameter("adpt::kdly")).toDouble());
    }
    catch(iconf_error& e)
    {
        QMessageBox::warning(this, "Error", e.what());
    }
}

void APZP1AlgorithmDesigner::applySettings()
{
    try
    {
        m_targetAlgorithm->setParameter("adpt::ampoly", ui->edAmPoly->text().toStdString());
        m_targetAlgorithm->setParameter("adpt::bmpoly", ui->edBmPoly->text().toStdString());
        m_targetAlgorithm->setParameter("adpt::ndr", ui->edRDegree->text().toStdString());
        m_targetAlgorithm->setParameter("adpt::nds", ui->edSDegree->text().toStdString());
        m_targetAlgorithm->setParameter("adpt::kdly", ui->edKDelay->text().toStdString());
    }
    catch(iconf_error& e)
    {
        QMessageBox::warning(this, "Error", e.what());
    }
}
